package com.bocai.freeman.model;

import com.bocai.freeman.model.bean.BaseBean;
import com.bocai.freeman.net.MyRetrofit;
import com.bocai.freeman.utils.StringUtil;
import com.trello.rxlifecycle.components.support.RxAppCompatActivity;

import cn.bocweb.net.BocRequestBuilder;
import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by admin on 2016/5/18.
 */
public class UserModel extends MyRetrofit {
    private RxAppCompatActivity mActivity;

    public UserModel(RxAppCompatActivity activity) {
        this.mActivity = activity;
    }

    public void register( String tel, String password, String code, Observer<BaseBean> observer) {
        String content = new BocRequestBuilder()
                .put("tel", tel)
                .put("code", code)
                .put("password", StringUtil.md5(password))
                .build();
        getGirlApi().register(content)
                .compose(mActivity.<BaseBean>bindToLifecycle())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    public void obtainCode( String tel, String type, Observer<BaseBean> observer) {
        String content = new BocRequestBuilder()
                .put("tel", tel)
                .put("type", type)
                .build();
        getGirlApi().obtainCode(content)
                .compose(mActivity.<BaseBean>bindToLifecycle())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    public void login( String tel, String password, Observer<BaseBean> observer) {
        String content = new BocRequestBuilder()
                .put("tel", tel)
                .put("password", StringUtil.md5(password))
                .build();
        getGirlApi().login(content)
                .compose(mActivity.<BaseBean>bindToLifecycle())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

    public void forgetPwd( String tel, String password, String code, Observer<BaseBean> observer) {
        String content = new BocRequestBuilder()
                .put("tel", tel)
                .put("password", StringUtil.md5(password))
                .put("code", code)
                .build();
        getGirlApi().forgetPwd(content)
                .compose(mActivity.<BaseBean>bindToLifecycle())
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(observer);
    }

}
